// graphdata.h: interface for the graphdata class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_GRAPHDATA_H__8B3E8D58_2610_400C_9004_3AA80BBB559B__INCLUDED_)
#define AFX_GRAPHDATA_H__8B3E8D58_2610_400C_9004_3AA80BBB559B__INCLUDED_
#include <afxtempl.h>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
typedef	double	xcoor;

struct _signalsline
{
    BYTE *sig;
    ULONG signalsnumber;

    _signalsline();
    ~_signalsline();
    void ReallocateSignalsNumber(ULONG asignalsnumber);
} ;

struct _marked_line
{
	unsigned __int64	x_relative;	//from graph zoom window
	unsigned __int64	x_true;		//assigned to edge
	CString signalname;	//assigned line to this signal edge
	BOOL	optimize;	//==FALSE no change in x_true coor == TRUE assign to signal edge
	WORD	signalID; 
};

struct RuleBorders
{
	unsigned long Start;
	unsigned long End;
	RuleBorders( unsigned long start, unsigned long end ){Start = start; End = end; };
	RuleBorders(){};
	~RuleBorders(){};
};

class graphdata  
{
friend class					ScenarioSignals;
friend struct					HighlightingRule;
public:
	int							InitGraphData				(	unsigned __int64	&global_delta, 
																unsigned __int64	&global_offset, 
																unsigned int	window_delta, 
																unsigned int	window_ratio,
                                                                unsigned long   signals_number,
																CString			NewTimeType);
	CString						GetStretchClkFormat			();
	__int64						GetOffset					();
	__int64						GetNearestRealCoordinates	( long x );
	CString						GetTrueCoordinates			( CPoint point );
	__int64                     GetTrueCoordinates          ( long coordX );
	CString						GetGroupName				();
	void						SetGroupName				(CString name);
	xcoor						GetDeltax					() const;
	//int						GetPolyLineArrayForClock	(int x,int y,WORD numofsignal,CPoint *p);
	int							FinilizeSignalInGraph		(ScenarioSignals* globalsignals, __int64 LastTime );
	void						SetOffset					(__int64 _offset);
	void						SetPageLength				(__int64 plength);
	//BOOL						CompareWithLastSignal		();
	BOOL						GetChangedFlagInSignal		(WORD signalpos,WORD	signalnumber);
	void						SetChangedFlagInSignal		(WORD signalnumber);
	BOOL						CompareBitWithSignalBit		(WORD signalnumber,BYTE bit);//Used nowhere
	void						SetDeltax					(xcoor x);
	int							PutSignalInGraph			(BYTE setbit, __int64 x_pos, WORD signal_number, HighlightingRule Rule);
	int							GetPolyLineArrayForSignal	(WORD signalpos,WORD signalnumber,CPoint *p );
	void						SetSignalBar				(WORD signalnumber,CPoint p);
	unsigned int				GetDeltay					();
	void						SetDeltay					(unsigned int cx);
	unsigned int				GetYOffset					();
	//void						SetTimeType					( CString NewTimeType );
	void						AddLine						(CString name,DWORD offset);
	void						AddSignal					();
	void						AddSignalsName				(ScenarioSignals* signalsnme);
	CString						GetSignalName				(DWORD pos);
	DWORD						GetLineOffset				(DWORD pos);
	CString						GetLineName					(DWORD pos);
	DWORD						GetNumberOfSignalsName		();
	DWORD						GetNumberOfLines			();
	DWORD						GetNumberOfSignals			();
	__int64						GetPageLength				();
	BYTE						GetBitInSignal				( WORD PositionInGraph, DWORD NumberOfSignal );
	void						PutBitInSignal				(BYTE bit,WORD place);
	void						RemoveAll					();
								graphdata					();
	virtual						~graphdata					();
	void						newsignal					();
	int							GetWindowCoordinate			(__int64 globalcoordinate) const;
	int							GetPreciseVerticalSizeOfSignal();
	CArray< RuleBorders, RuleBorders >* GetRuleBordersForSignal( int NumberOfSignal );
	void						SetTotalSize				( __int64 NewTotalSize );
	__int64						GetTotalSize				();
	__int64						GetSizeInPixels				( __int64 Size );
protected:
	void						AddFlagsToSignals			();
	void						ClearSignalsLine			(_signalsline *sig);
	bool						ValueFulfilingConditionsOfRule( __int64 Value, HighlightingRule Rule );

//--------- for graphic part
	xcoor						*lastbitcoordinatesx;
	unsigned int				*lastbitcoordinatesy;
	_signalsline				lastbitstatus;
	unsigned int				deltay;
	BYTE						yoffset;
	xcoor						deltax;
	__int64						pagelength;

//data base for signals
	CArray<CString,CString>				signalsname;
	CArray<CString,CString>				linename;//line = signal period = simplegroup
	CArray<DWORD,DWORD>					linepos;
	_signalsline						tempsignal;
	_signalsline						tempflags;// =0 - init state; 10< .. <20 = one time change;>=20 too many changes
	CString								TimeType;

//---------- most important signal data last updates
private:
	CArray<_signalsline	,_signalsline>	signals_status;
	DWORD                               *signal_start_pos;
	_signalsline						last_signal_status;
	CArray<__int64,__int64>					signals_cut_x;
	DWORD								windowratio;
	CArray< RuleBorders, RuleBorders >  *RuleBordersForSignal;
	__int64								*LastAbsoluteValue;
	__int64								TotalSize;
	ULONG								NumberOfSignals;
public:
	_marked_line						_1stmark,_2ndmark;
	DWORD								graphdelta;
	__int64								globaldelta;
	__int64								globaloffset;
	DWORD								windowdelta;
	const static long					YSizeOfSignalDivider = 3;

//----document settings
protected:
	CString								groupname;
};

#endif // !defined(AFX_GRAPHDATA_H__8B3E8D58_2610_400C_9004_3AA80BBB559B__INCLUDED_)
